import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { fromEvent } from 'rxjs';
import { ViewsserviceService } from '../../services/viewsservice.service'

@Component({
  selector: 'app-footer',
  templateUrl: './footer.component.html',
  styleUrls: ['./footer.component.styl']
})
export class FooterComponent implements OnInit {
  public nzSpan: number; // 栅格数
  @ViewChild('footerId') footerId: ElementRef;
  constructor(public service: ViewsserviceService) { }

  ngOnInit() {
    var obj: object = {
      judge: 1,// 不说了，自己看api
      windowWidth: 768, // 要监听的窗口宽度
      trueValue: 24, // 当判断为 true 时要返回的参数
      flaseValue: 6, //当判断为 flase 时要返回的参数
    }
    this.service.getInitWindowWidth(obj).subscribe((event) => {
      this.nzSpan = event;
    })
    // 监听窗口宽度(当窗口大小发生变化时)
    fromEvent(window, 'resize')
      //.debounceTime(100) // 以免频繁处理
      .subscribe((event) => {
        this.service.getInitWindowWidth(obj).subscribe((event) => {
          this.nzSpan = event;
        })
      });

      // fromEvent(window, 'scroll').subscribe((event) => {
      //   var window: any = event.currentTarget;
      //   var getScroll: number = window.scrollY;
      //   var doc = this.footerId.nativeElement;
      //   // console.log(getScroll)
      //   if (getScroll > 500) {
      //     doc.style.display = "block";
      //     // console.log("====");
      //   } else {
      //     doc.style.display = "none";
      //     // console.log("+++++");
      //   }
      // })
  }
  ngAfterViewInit(): void {
    //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
    //Add 'implements AfterViewInit' to the class.
    
  }
}
